package edu.jptest.serviceImp;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import edu.jptest.bean.QuestionType;
import edu.jptest.dao.QuestionTypeDAO;
import edu.jptest.service.IQuestionTypeService;

public class QuestionTypeService implements IQuestionTypeService {

	// 插入问题类型
	public boolean insertQuestionType(QuestionType questionType) {
		QuestionTypeDAO questionTypeDao = new QuestionTypeDAO();
		return questionTypeDao.insertQuestionType(questionType);
	}

	// 删除问题类型
	public boolean deleteQuestionType(int questionType_id) {
		QuestionTypeDAO questionTypeDao = new QuestionTypeDAO();
		return questionTypeDao.deleteQuestionType(questionType_id);
	}

	// 更改问题类型
	public boolean updateQuestionType(QuestionType questionType) {
		QuestionTypeDAO questionTypeDao = new QuestionTypeDAO();
		return questionTypeDao.updateQuestionType(questionType);
	}

	// 通过问题类型id，查询问题类型对象
	public QuestionType getquestionTypeByquestionTypeId(int questionType_id) {
		QuestionTypeDAO questionTypeDao = new QuestionTypeDAO();
		return questionTypeDao.getquestionTypeByquestionTypeId(questionType_id);
	}

	// 通过大题型、小题型，查询题型id
	public int getQuestionTypeIdByContent(String type, String content) {
		QuestionTypeDAO questionTypeDao = new QuestionTypeDAO();
		return questionTypeDao.getQuestionTypeIdByContent(type, content);
	}

	// 获得所有大题型
	public List<String> getQuestionTypes() {
		QuestionTypeDAO questionTypeDao = new QuestionTypeDAO();
		return questionTypeDao.getQuestionTypes();
	}

	// 通过大题型，查询所具有的小题型
	public List<String> getQuestionTypesContentByType(String questionType_type) {
		QuestionTypeDAO questionTypeDao = new QuestionTypeDAO();
		return questionTypeDao.getQuestionTypesContentByType(questionType_type);
	}

	// 获得所有问题类型
	public List<QuestionType> getAllQuestionTypes() {
		QuestionTypeDAO questionTypeDao = new QuestionTypeDAO();
		List<Integer> questionTypeIdList = new ArrayList<Integer>();
		List<QuestionType> questionTypeList = new ArrayList<QuestionType>();
		questionTypeIdList = questionTypeDao.getAllQuestionTypesId();
		Iterator<Integer> it = questionTypeIdList.iterator();
		while (it.hasNext()) {
			int typeId = (Integer) it.next();
			questionTypeList.add(questionTypeDao
					.getquestionTypeByquestionTypeId(typeId));
		}
		return questionTypeList;
	}

}
